/*
This file is part of SmartShopper

SmartShopper is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

SmartShopper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with vlc-remote.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <QtGui/QApplication>
#include <QtDeclarative>
#include "databaseconnect.h"
#include "shoplistmodel.h"
#include "shoplistcontrol.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    //init path for data

#if defined (Q_WS_S60)
    const QString cDatabasePath = "\\data\\smartshopper\\";
#endif
    QString mDataPath;
#if defined(Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN)
//    QString lDatabasePath = QDir::homePath() + QString("/.smartshopper/");
//    mDataPath = lDatabasePath + QString(cDatabaseFile);
    mDataPath = QString("/home/user/.smartshopper/");
    QDir dr(mDataPath);
    if (!(dr.exists()))
        dr.mkpath(mDataPath);
#elif defined (Q_WS_S60)
//    mDataPath = QDir::currentPath() + QString("\\") + QString(cDatabaseFile);
    QString homePath = QDir::currentPath(); // to detect home drive
    mDataPath = homePath.left(2) + QString(cDatabasePath);// + QString(cDatabaseFile);
    QDir dr(cDatabasePath);
    if (!(dr.exists()))
        dr.mkpath(cDatabasePath);
#else
    mDataPath = QDir::currentPath() + QString("\\") + QString(cDatabaseFile);
#endif

    // init DB
    DatabaseConnect db(mDataPath);

//  then we init List models and expose them to QML
    ShopListModel listModel;
    ShopListControl listControl(&listModel);


    QDeclarativeView view;
    QObject::connect(view.engine(),SIGNAL(quit()),&app,SLOT(quit()));
    QDir::setCurrent(app.applicationDirPath());
    QString sPath = app.applicationDirPath() + ("/qml/main.qml");
    view.setSource(QUrl(sPath));
//    QDeclarativeEngine* engine = view.engine();
    QDeclarativeContext* context = view.rootContext();
//    context->setContextProperty("listModel", QVariant::fromValue(model.getLists()));
    context->setContextProperty("listModel", &listModel);
//    context->setContextProperty("sortModel", QVariant::fromValue(model.getSortList()));
    context->setContextProperty("listControl", &listControl);
//    context->setContextProperty("listModel", QVariant::fromValue(dataList));
    view.showFullScreen();
    return app.exec();
}
